package com.example.demo.model.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

@Getter
public enum PaperStatusEnum {
    DRAFT(0, "草稿"),
    SUBMITTED(1, "已提交"),
    APPROVED(2, "已审核"),
    REVISING(3, "需修改"),
    REJECTED(4, "已拒绝"),
    PENDING_REVIEW(5, "待审核");

    private final int code;
    private final String description;

    private static final Map<Integer, PaperStatusEnum> CODE_MAP = Arrays.stream(values())
            .collect(Collectors.toMap(PaperStatusEnum::getCode, e -> e));

    PaperStatusEnum(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public static PaperStatusEnum fromCode(int code) {
        PaperStatusEnum status = CODE_MAP.get(code);
        if (status == null) {
            throw new IllegalArgumentException("无效的论文状态码: " + code);
        }
        return status;
    }

    public boolean isFinalStatus() {
        return this == APPROVED || this == REJECTED;
    }

    public boolean canBeModified() {
        return this == DRAFT || this == REVISING;
    }

    public boolean canBeDeleted() {
        return this == DRAFT;
    }
}